Text was provided by: https://freeditorial.com/en/books/the-wind-in-the-willows/related-books
The 4 BEST FRIENDS that anyone could have.
willow_text <- pdf_text("ww.pdf")
willow_tidy <- data.frame(willow_text) %>%
mutate(text_full = str_split(willow_text, pattern = '\\n')) %>%
unnest(text_full) %>%
mutate(text_full = str_trim(text_full))
willow_df <- willow_tidy %>%
slice(-(1:4))
willow_tokens <- willow_df %>%
unnest_tokens(word, text_full) %>%
select(-willow_text)
willow_nonstop_words <- willow_tokens %>%
anti_join(stop_words)
nonstop_counts <- willow_nonstop_words %>%
count(word)
top_200 <- nonstop_counts %>%
arrange(-n) %>%
slice(1:200)
top_50 <- nonstop_counts %>%
arrange(-n) %>%
slice(1:50)
top_100 <- nonstop_counts %>%
arrange(-n) %>%
slice(1:100)
top_100_wo <- nonstop_counts %>%
arrange(-n) %>%
slice(1:100) %>%
slice(-(1:4))
top_5_words <- nonstop_counts %>%
arrange(-n) %>%
slice(1:5)
ww_cloud <- ggplot(data = top_100_wo, aes(label = word)) +
geom_text_wordcloud(aes(color = n, size = n), shape = "diamond") +
scale_size_area(max_size = 6) +
scale_color_gradientn(colors = c("darkgreen","blue","purple")) +
theme_minimal()
river <- readJPEG("river.jpg")
ww_cloud_50 <- ggplot(data = top_50, aes(label = word)) +
geom_text_wordcloud(aes(color = n, size = n), shape = "oval") +
scale_size_area(max_size = 12) +
scale_color_gradientn(colors = c("hotpink4","dodgerblue2","deepskyblue", "darkgreen")) +
theme_minimal()
ww_cloud_50
ww <- ggdraw() +
draw_image(river) +
draw_plot(ww_cloud_50)
ww
ww_cloud_100 <- ggplot(data = top_100, aes(label = word)) +
geom_text_wordcloud(aes(color = n, size = n), shape = "oval") +
scale_size_area(max_size = 8) +
scale_color_gradientn(colors = c("darkgreen","steelblue1","deepskyblue")) +
theme_minimal()
willow_afinn <- willow_nonstop_words %>%
inner_join(get_sentiments("afinn"))
willow_afinn_count <- willow_afinn %>%
count(word, value)
willow_nrc <- willow_nonstop_words %>%
inner_join(get_sentiments("nrc"))
willow_nrc_counts <- willow_nrc %>%
count(sentiment)
#ggplot(data = willow_nrc_counts, aes(x = sentiment, y = n)) +
#geom_col() +
#coord_flip()
ggplot(data = willow_afinn_count, aes(x = value, y = n)) +
geom_col(aes(color = value)) +
theme_minimal() +
labs(x = "Afinn Values",
y = "Observations",
title = "Afinn Analysis Wind in the Willows") +
theme(plot.title = element_text(size = 14,
face = "bold",
hjust = 0.5),
axis.title.y = element_text(size = 14))